package www.tshu.servlet;

import www.tshu.pojo.PI;
import www.tshu.pojo.User;
import www.tshu.service.BookService;
import www.tshu.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletMoneyById")
public class ServletMoneyById extends HttpServlet {
    private BookService bookService = new BookServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String unum=(String) req.getSession().getAttribute("unum");
        User user = new User(unum);
        PI pi = new PI(user);
        Double money = bookService.getMoneyById(pi);
        req.setAttribute("money",money);
        req.getRequestDispatcher("/user/moneyById.jsp").forward(req,resp);
    }
}
